package com.health.controller;

import com.health.pojo.ExamineOrder;
import com.health.pojo.HealthAttributes;
import com.health.pojo.Users;
import com.health.service.HealthComboService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//  点击下拉框显示体检项信息
@WebServlet(value = "/medicalPlanOption")
public class MedicalPlanOptionServlet extends HttpServlet {
    HealthComboService healthComboService = new HealthComboService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取套餐id
        String examineId = request.getParameter("examineId");
        // 查询套餐对应的健康项
        List<HealthAttributes> attributesList = healthComboService.selectOptionByAttribute(examineId);
        //  查询套餐以及检查项数据
        List<ExamineOrder> examineOrderList = healthComboService.selectByCombo();
        // 设置当前套餐id的套餐价格
        for (ExamineOrder examineOrder : examineOrderList) {
            if (examineOrder.getExamineId() == Integer.parseInt(examineId)) {
                request.setAttribute("price", examineOrder.getExaminePrice());
                break;
            }
        }
        //  设置到请求域中(套餐项)
        request.setAttribute("examineOrderList", examineOrderList);
        // 设置到数据域(健康项)
        request.setAttribute("attributesList", attributesList);
        // 设置侧边栏状态
        request.setAttribute("asideStatus", 2);
//        request.setAttribute("examineId", examineId);
        request.setAttribute("index", request.getParameter("index"));
        request.getRequestDispatcher("/restrictedPages/main.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
